package com.cvit.service;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cvit.dao.vPaycountMapper;
import com.cvit.model.ExcelBean;
import com.cvit.model.vPaycount;
import com.cvit.utils.ExcelUtil;

@Service
public class PayCountService {

	@Autowired
	vPaycountMapper vPaycountMapper;
	
	/**
	 * 统计方法
	 * */
	public List<vPaycount> Count(vPaycount vpaycount) {
		List<vPaycount> list=vPaycountMapper.selectCount(vpaycount);
		return list;
	}
	
	/**
	 * 总金额
	 * */
	public String Price(vPaycount vpaycount) {
		String p="0";
		List<vPaycount> list=vPaycountMapper.selectPrice(vpaycount);
		System.out.println(list.get(0));
		if (list.get(0)!=null) {
			p=list.get(0).getPrice().toString();
		}
		return p;
	}
	
	/**
	 * 导出Excel-School and major(school和major可以为空)
	 * */
	public XSSFWorkbook exportExcelInfoBySchoolAndMajor(String ordersData,vPaycount vpaycount) throws InvocationTargetException, ClassNotFoundException, IntrospectionException, ParseException, IllegalAccessException {  
	    //根据条件查询数据，把数据装载到一个list中  
		List<vPaycount> orders = vPaycountMapper.selectCount(vpaycount);
	    List<ExcelBean> excel=new ArrayList<>();
	    Map<Integer,List<ExcelBean>> map=new LinkedHashMap<>();
	    XSSFWorkbook xssfWorkbook=null;
	    //设置标题栏
//	    excel.add(new ExcelBean("考生号","examineeId",0));
//	    excel.add(new ExcelBean("身份证号","cardId",0));
//	    excel.add(new ExcelBean("姓名","name",0));
	    excel.add(new ExcelBean("报考学校","school",0));
	    excel.add(new ExcelBean("填报专业","major",0));
	    excel.add(new ExcelBean("人数","payType",0));
	    excel.add(new ExcelBean("价格","price",0));
//	    excel.add(new ExcelBean("时间","startTime",0));
	    map.put(0, excel);
	    String sheetName = ordersData;
	    //调用ExcelUtil的方法
	    xssfWorkbook = ExcelUtil.createExcelFile(vPaycount.class, orders, map, sheetName);
	    return xssfWorkbook;
	}
}
